<template>
  <el-date-picker
    ref="domDate"
    v-model="value"
    v-bind="$attrs"
    :type="dateType"
    :name="'c' + meta.columnId"
    :format="format"
    :value-format="valueFormat"
    :clearable="clearable"
  >
  </el-date-picker>
</template>

<script setup lang="ts" generic="T extends object">
  /**
   * 年月日
   */
  import type { IFormItemProps } from '../../map'
  import { itemController } from '../../map'

  defineOptions({
    name: 'nf-el-from-item-date2',
    inheritAttrs: false,
  })

  
  type IDatePickerType =
    | 'year'
    | 'month'
    | 'date'
    | 'dates'
    | 'week'
    | 'datetime'
    | 'datetimerange'
    | 'daterange'
    | 'monthrange'

  const props = withDefaults(defineProps<IFormItemProps<T> & {
    format?: string,
    valueFormat?: string,
  }>(), {
    meta: () => {
      return {
        colName: ''
      }
    },
    model: () => {
      return {} as T
    },
    clearable: true,
    format: 'YYYY-MM-DD',
    valueFormat: 'YYYY-MM-DD'
  })
  
  const { value } = itemController(props)

  // 根据类型判断是否为数组，判断是否 使用范围。
  let dateType: IDatePickerType = 'date'
  if (props.meta.controlType == 125 ) {
    dateType = 'daterange'
    if (!Array.isArray(value.value)) {
      value.value = []
    }
  } else {
    if (Array.isArray(value.value)) {
      value.value = ''
    }
  }
 
</script>
